﻿using PLCS.Application.Contracts.ConfigApp.Dtos;
using PLCS.Application.Contracts.EquipmentApp.Dtos;
using PLCS.Application.Contracts.PLCConfigApp.Dtos;
using PLCS.Client.IService.ConfigManager;
using PLCS.Domain.Shared.Enums;

using System.Collections.ObjectModel;
using System.Numerics;

using Volo.Abp.Application.Dtos;

namespace PLCS.Client.Service.ConfigManager;

public class ConfigService : BaseService<ConfigDto, ConfigEditDto>, IConfigService
{
    public override async Task<IEnumerable<ConfigDto>> GetListAsync()
    {
        RequestParam requestParam = new(method: Method.Get, route: $"config/configlist");
        var apiRes = await restClient.ExecuteAsync<ObservableCollection<ConfigDto>>(requestParam);
        if (apiRes.Status)
            return apiRes.Data;
        else
            return Enumerable.Empty<ConfigDto>();
    }

    public async Task<string> GetConfigByNameAsync(string name)
    {
        RequestParam requestParam = new(method: Method.Get, route: $"config/configByName?name={name}");
        var apiRes = await restClient.ExecuteAsync<string>(requestParam);
        if (apiRes.Status)
            return apiRes.Data;
        else
            return string.Empty;
    }

    public async Task<PagedResultDto<ConfigDto>> GetListBySearchAsync(int skipCount, int maxResultCount, string? name)
    {
        var route = $"config/bySearch?SkipCount={skipCount}&MaxResultCount={maxResultCount}";
        if (!string.IsNullOrEmpty(name))
            route += $"&name={name}";

        RequestParam requestParam = new(method: Method.Get, route: route);
        var apiRes = await restClient.ExecuteAsync<PagedResultDto<ConfigDto>>(requestParam);
        if (apiRes.Status)
            return apiRes.Data;
        else
            return new PagedResultDto<ConfigDto>();
    }
}